import { setListFn, numMap, numEnMap } from './../../../utils';

import { printUnitNum } from './../adjustingSetting/printUnit';

const printUnitList: any = [];

for (let i = 0; i < printUnitNum; i++) {
  const key = i + 1;

  printUnitList.push({
    labelZh: `${numMap[key]}色`,
    labelEn: `${numEnMap[key]}-color`,
    // rutodo
    readFunId: `${key}xxxGet`,
    readWriteFunId: `${key}xxxSet`,
    confirmFunId: `${key}xxxSeal`,
    clearFunId: `${key}xxxUpdate`
  });
}

const setPrintUnitListFn = (list: any = [], key: any = '') => {
  if (list && list.length) {
    const newList: any = [];

    const readWriteFunIdList: any = [];

    const confirmFunIdList: any = [];

    const clearFunIdList: any = [];

    for (const item of list) {
      const {
        labelZh = null,
        labelEn = null,
        readFunId = null,
        confirmFunId = null,
        readWriteFunId = null,
        clearFunId = null
      } = item;

      const sList: any = [
        {
          inputType: 'read',
          labelZh: '实际值',
          labelEn: 'Actual Value',labelRu: `Фактическое значение`,
          funId: readFunId === null ? null : `${readFunId.replace('xxx', key)}`
        },
        {
          inputType: 'readWrite',
          labelZh: '设置值',
          labelEn: 'Set Value',
          funId:
            readWriteFunId === null
              ? null
              : `${readWriteFunId.replace('xxx', key)}`,
          defaultValGetFunId:
            readWriteFunId === null
              ? null
              : `${readWriteFunId.replace('xxx', key)}`,
          blurChange: true
        },
        {
          inputType: 'btnBool',
          labelZh: '确认',
          labelEn: 'Confirm',
          funId:
            confirmFunId === null
              ? null
              : `${confirmFunId.replace('xxx', key)}`,
          clickType: 'startAndEnd',
          writeVal: 1,
          clickTime: 0
        }
      ];

      if (key === 'ColorPhase') {
        sList.push({
          inputType: 'btnBool',
          labelZh: '清零',
          labelEn: 'Zeroing',labelRu: 'Сброс на ноль',
          funId:
            clearFunId === null ? null : `${clearFunId.replace('xxx', key)}`,
          clickType: 'startAndEnd',
          writeVal: 1,
          clickTime: 0,
          styleType: 'whiteBgColor'
        });
      }

      newList.push({
        labelZh,
        labelEn,
        type: 'input',
        list: setListFn(sList)
      });

      readWriteFunIdList.push({
        inputType: 'readWrite',
        funId:
          readWriteFunId === null
            ? null
            : `${readWriteFunId.replace('xxx', key)}`
      });

      confirmFunIdList.push({
        funId:
          confirmFunId === null ? null : `${confirmFunId.replace('xxx', key)}`,
        clickType: 'startAndEnd',
        writeVal: 1
      });

      if (key === 'ColorPhase') {
        clearFunIdList.push({
          funId:
            clearFunId === null ? null : `${clearFunId.replace('xxx', key)}`,
          clickType: 'startAndEnd',
          writeVal: 1
        });
      }
    }

    const rList: any = [
      {
        inputType: 'write',
        labelZh: '设置值',
        blurChange: true,
        writeOtherFunIdList: readWriteFunIdList,
        updateClear: true
      },
      {
        inputType: 'btnOtherOperate',
        labelZh: '统归',
        labelEn: 'Setting All Values',labelRu: 'Единый возврат',
        writeOtherFunIdList: confirmFunIdList
      }
    ];

    if (key === 'ColorPhase') {
      // console.log(clearFunIdList)
      rList.push({
        inputType: 'btnOtherOperate',
        labelZh: '统清零',
        labelEn: 'Zeroing All Values',labelRu: 'Единый сброс на ноль',
        writeOtherFunIdList: clearFunIdList,
        styleType: 'whiteBgColor'
      });
    }

    return {
      list: newList,
      labelList: [
        {
          labelZh: '统归',
          labelEn: 'Setting All Values',labelRu: 'Единый возврат',
          type: 'input',
          list: setListFn(rList)
        }
      ]
    };
  }

  return { list, labelList: [] };
};

const totalHomingList = [
  {
    labelZh: `轴向`,
    labelEn: `Axial`,
    labelRu: `Осевое направление`,
    id: `ColorHorizontalShift`,
    type: 'common'
  },
  {
    labelZh: `径向`,
    labelEn: `Radial`,
    labelRu: `Радиальный`,
    id: `ColorPhase`,
    type: 'common'
  },
  {
    labelZh: `压印`,
    labelEn: 'Embossing',
    labelRu: 'Тиснение',
    id: `ColorPrintingGap`,
    type: 'common'
  }
];

const setTotalHomingListFn = (list: any) => {
  const newList: any = [];

  if (list && list.length) {
    for (const item of list) {
      const { id = null } = item;

      const { list = [], labelList = [] } = setPrintUnitListFn(
        printUnitList,
        id
      );

      if (id) {
        newList.push({
          ...item,
          list,
          labelList
        });
      }
    }
  }

  return newList;
};

export default {
  type: 'totalHoming',
  labelZh: '印刷单元总归位',
  labelEn: 'Printing Units Complete Homing',
  labelRu: 'Общий возврат на место блока печати',
  // saveParameters: true,
  list: setTotalHomingListFn(totalHomingList)
};
